{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 168,
   "metadata": {},
   "outputs": [],
   "source": [
    "from settings import DBSelector\n",
    "import pandas as pd\n",
    "import pymongo\n",
    "from pyecharts.charts import Bar\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 169,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "been called\n"
     ]
    }
   ],
   "source": [
    "DB=DBSelector()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 170,
   "metadata": {},
   "outputs": [],
   "source": [
    "engine = DB.get_engine('db_stock','qq')\n",
    "# 堆叠图\n",
    "\n",
    "df = pd.read_sql('tb_bond_jisilu',con=engine)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'str' object has no attribute 'get'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-3-aeac1c9caa37>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m     48\u001b[0m             \u001b[0mretAAA\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     49\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 50\u001b[1;33m \u001b[0mbar\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mBar\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'可转债价格分布'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     51\u001b[0m \u001b[0mbar\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'A+'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mret_A_add\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mis_stack\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0myaxis_max\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m11\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     52\u001b[0m \u001b[0mbar\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0madd\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'AA-'\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mvalue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mretAA_\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0mis_stack\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0myaxis_max\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m11\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pyecharts\\charts\\chart.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, init_opts)\u001b[0m\n\u001b[0;32m    161\u001b[0m \u001b[1;32mclass\u001b[0m \u001b[0mRectChart\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mChart\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    162\u001b[0m     \u001b[1;32mdef\u001b[0m \u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0minit_opts\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mtypes\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInit\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mInitOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 163\u001b[1;33m         \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    164\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mxAxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mAxisOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0myAxis\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mAxisOpts\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    165\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pyecharts\\charts\\chart.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, init_opts)\u001b[0m\n\u001b[0;32m     12\u001b[0m             \u001b[0mtemp_opts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     13\u001b[0m             \u001b[0minit_opts\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mtemp_opts\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 14\u001b[1;33m         \u001b[0msuper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__init__\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0minit_opts\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     15\u001b[0m         self.colors = (\n\u001b[0;32m     16\u001b[0m             \u001b[1;34m\"#c23531 #2f4554 #61a0a8 #d48265 #749f83 #ca8622 #bda29a #6e7074 \"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pyecharts\\charts\\base.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, init_opts)\u001b[0m\n\u001b[0;32m     27\u001b[0m             \u001b[0m_opts\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minit_opts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mopts\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     28\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 29\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mwidth\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_opts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"width\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"900px\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     30\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mheight\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_opts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"height\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m\"500px\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m     31\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mrenderer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0m_opts\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"renderer\"\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mRenderType\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mCANVAS\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'str' object has no attribute 'get'"
     ]
    }
   ],
   "source": [
    "\n",
    "result ={}\n",
    "for name,grades in df.groupby('评级'):\n",
    "#     print(name,grades[['可转债名称','可转债价格']])\n",
    "    for each in grades['可转债价格']:\n",
    "        result.setdefault(name,[])\n",
    "        result[name].append(each)\n",
    "        \n",
    "        \n",
    "# 确定价格的范围\n",
    "\n",
    "value = [str(i) for i in range(85,140)]\n",
    "ret = [0]*len(value)\n",
    "ret1 = dict(zip(value,ret))\n",
    "\n",
    "ret_A_add = ret1.copy()\n",
    "for item in result['A+']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            ret_A_add[k]+=1\n",
    "            \n",
    "retAA_ = ret1.copy()\n",
    "for item in result['AA-']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA_[k]+=1\n",
    "\n",
    "retAA = ret1.copy()\n",
    "for item in result['AA']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA[k]+=1\n",
    "            \n",
    "retAA_add = ret1.copy()\n",
    "for item in result['AA+']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA_add[k]+=1\n",
    "            \n",
    "retAAA = ret1.copy()\n",
    "for item in result['AAA']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAAA[k]+=1\n",
    "\n",
    "bar = Bar('可转债价格分布')\n",
    "bar.add('A+',value,list(ret_A_add.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA-',value,list(retAA_.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA',value,list(retAA.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA+',value,list(retAA_add.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AAA',value,list(retAAA.values()),is_stack=True,yaxis_max=11)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from  setting import get_mysql_conn,get_engine\n",
    "import pandas as pd\n",
    "import pymongo\n",
    "from pyecharts import Geo,Style,Map\n",
    "engine = get_engine('db_stock',local='local')\n",
    "# 堆叠图\n",
    "from pyecharts import Bar\n",
    "df = pd.read_sql('tb_bond_jisilu',con=engine)\n",
    "\n",
    "result ={}\n",
    "for name,grades in df.groupby('评级'):\n",
    "#     print(name,grades[['可转债名称','可转债价格']])\n",
    "    for each in grades['可转债价格']:\n",
    "        result.setdefault(name,[])\n",
    "        result[name].append(each)\n",
    "        \n",
    "        \n",
    "# 确定价格的范围\n",
    "\n",
    "value = [str(i) for i in range(85,140)]\n",
    "ret = [0]*len(value)\n",
    "ret1 = dict(zip(value,ret))\n",
    "\n",
    "ret_A_add = ret1.copy()\n",
    "for item in result['A+']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            ret_A_add[k]+=1\n",
    "            \n",
    "retAA_ = ret1.copy()\n",
    "for item in result['AA-']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA_[k]+=1\n",
    "\n",
    "retAA = ret1.copy()\n",
    "for item in result['AA']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA[k]+=1\n",
    "            \n",
    "retAA_add = ret1.copy()\n",
    "for item in result['AA+']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAA_add[k]+=1\n",
    "            \n",
    "retAAA = ret1.copy()\n",
    "for item in result['AAA']:\n",
    "    for k in ret1:\n",
    "        if float(k)+0.5>item and float(k)-0.5<=item:\n",
    "            retAAA[k]+=1\n",
    "\n",
    "bar = Bar('可转债价格分布')\n",
    "bar.add('A+',value,list(ret_A_add.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA-',value,list(retAA_.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA',value,list(retAA.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AA+',value,list(retAA_add.values()),is_stack=True,yaxis_max=11)\n",
    "bar.add('AAA',value,list(retAAA.values()),is_stack=True,yaxis_max=11)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "list2 = [\n",
    "    {\"value\": 12, \"percent\": 12 / (12 + 3)},\n",
    "    {\"value\": 23, \"percent\": 23 / (23 + 21)},\n",
    "    {\"value\": 33, \"percent\": 33 / (33 + 5)},\n",
    "    {\"value\": 3, \"percent\": 3 / (3 + 52)},\n",
    "    {\"value\": 33, \"percent\": 33 / (33 + 43)},\n",
    "]\n",
    "\n",
    "list3 = [\n",
    "    {\"value\": 3, \"percent\": 3 / (12 + 3)},\n",
    "    {\"value\": 21, \"percent\": 21 / (23 + 21)},\n",
    "    {\"value\": 5, \"percent\": 5 / (33 + 5)},\n",
    "    {\"value\": 52, \"percent\": 52 / (3 + 52)},\n",
    "    {\"value\": 43, \"percent\": 43 / (33 + 43)},\n",
    "]\n",
    "\n",
    "c = (\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))\n",
    "    .add_xaxis([1, 2, 3, 4, 5])\n",
    "    .add_yaxis(\"product1\", list2, stack=\"stack1\", category_gap=\"50%\")\n",
    "    .add_yaxis(\"product2\", list3, stack=\"stack1\", category_gap=\"50%\")\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(\n",
    "            position=\"right\",\n",
    "            formatter=JsCode(\n",
    "                \"function(x){return Number(x.data.percent * 100).toFixed() + '%';}\"\n",
    "            ),\n",
    "        )\n",
    "    )\n",
    "    .render(\"stack_bar_percent.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>可转债代码</th>\n",
       "      <th>可转债名称</th>\n",
       "      <th>可转债价格</th>\n",
       "      <th>正股名称</th>\n",
       "      <th>正股代码</th>\n",
       "      <th>正股现价</th>\n",
       "      <th>正股涨跌幅</th>\n",
       "      <th>最新转股价</th>\n",
       "      <th>溢价率</th>\n",
       "      <th>可转债涨幅</th>\n",
       "      <th>...</th>\n",
       "      <th>评级</th>\n",
       "      <th>下修提示</th>\n",
       "      <th>下调次数</th>\n",
       "      <th>转债剩余占总市值比</th>\n",
       "      <th>剩余规模</th>\n",
       "      <th>发行规模</th>\n",
       "      <th>股东配售率</th>\n",
       "      <th>强赎标志</th>\n",
       "      <th>强赎日期</th>\n",
       "      <th>更新日期</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>113035</td>\n",
       "      <td>福莱转债</td>\n",
       "      <td>262.50</td>\n",
       "      <td>福莱特</td>\n",
       "      <td>601865</td>\n",
       "      <td>44.43</td>\n",
       "      <td>8.90</td>\n",
       "      <td>13.56</td>\n",
       "      <td>-19.88</td>\n",
       "      <td>5.08</td>\n",
       "      <td>...</td>\n",
       "      <td>AA</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td>1.7</td>\n",
       "      <td>14.500</td>\n",
       "      <td>14.500</td>\n",
       "      <td>92.910</td>\n",
       "      <td>X</td>\n",
       "      <td>None</td>\n",
       "      <td>2020-11-02 15:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>113585</td>\n",
       "      <td>寿仙转债</td>\n",
       "      <td>151.80</td>\n",
       "      <td>寿仙谷</td>\n",
       "      <td>603896</td>\n",
       "      <td>46.75</td>\n",
       "      <td>4.12</td>\n",
       "      <td>28.68</td>\n",
       "      <td>-6.88</td>\n",
       "      <td>4.52</td>\n",
       "      <td>...</td>\n",
       "      <td>AA-</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td>5.4</td>\n",
       "      <td>3.600</td>\n",
       "      <td>3.600</td>\n",
       "      <td>82.309</td>\n",
       "      <td>X</td>\n",
       "      <td>None</td>\n",
       "      <td>2020-11-02 15:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>128115</td>\n",
       "      <td>巨星转债</td>\n",
       "      <td>207.00</td>\n",
       "      <td>巨星科技</td>\n",
       "      <td>002444</td>\n",
       "      <td>27.18</td>\n",
       "      <td>4.94</td>\n",
       "      <td>12.28</td>\n",
       "      <td>-6.48</td>\n",
       "      <td>2.73</td>\n",
       "      <td>...</td>\n",
       "      <td>AA</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td>3.3</td>\n",
       "      <td>9.730</td>\n",
       "      <td>9.730</td>\n",
       "      <td>74.920</td>\n",
       "      <td>X</td>\n",
       "      <td>None</td>\n",
       "      <td>2020-11-02 15:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>113586</td>\n",
       "      <td>上机转债</td>\n",
       "      <td>227.58</td>\n",
       "      <td>上机数控</td>\n",
       "      <td>603185</td>\n",
       "      <td>80.50</td>\n",
       "      <td>-2.08</td>\n",
       "      <td>33.30</td>\n",
       "      <td>-5.86</td>\n",
       "      <td>-2.24</td>\n",
       "      <td>...</td>\n",
       "      <td>AA-</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td>3.6</td>\n",
       "      <td>6.650</td>\n",
       "      <td>6.650</td>\n",
       "      <td>85.553</td>\n",
       "      <td>X</td>\n",
       "      <td>None</td>\n",
       "      <td>2020-11-02 15:03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>123055</td>\n",
       "      <td>晨光转债</td>\n",
       "      <td>140.65</td>\n",
       "      <td>晨光生物</td>\n",
       "      <td>300138</td>\n",
       "      <td>17.67</td>\n",
       "      <td>11.98</td>\n",
       "      <td>12.25</td>\n",
       "      <td>-2.49</td>\n",
       "      <td>6.15</td>\n",
       "      <td>...</td>\n",
       "      <td>AA-</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>6.300</td>\n",
       "      <td>6.300</td>\n",
       "      <td>76.640</td>\n",
       "      <td>X</td>\n",
       "      <td>None</td>\n",
       "      <td>2020-11-02 15:03</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    可转债代码 可转债名称   可转债价格  正股名称    正股代码   正股现价  正股涨跌幅  最新转股价    溢价率  可转债涨幅  ...  \\\n",
       "0  113035  福莱转债  262.50   福莱特  601865  44.43   8.90  13.56 -19.88   5.08  ...   \n",
       "1  113585  寿仙转债  151.80   寿仙谷  603896  46.75   4.12  28.68  -6.88   4.52  ...   \n",
       "2  128115  巨星转债  207.00  巨星科技  002444  27.18   4.94  12.28  -6.48   2.73  ...   \n",
       "3  113586  上机转债  227.58  上机数控  603185  80.50  -2.08  33.30  -5.86  -2.24  ...   \n",
       "4  123055  晨光转债  140.65  晨光生物  300138  17.67  11.98  12.25  -2.49   6.15  ...   \n",
       "\n",
       "    评级 下修提示 下调次数  转债剩余占总市值比    剩余规模    发行规模   股东配售率 强赎标志  强赎日期  \\\n",
       "0   AA         0        1.7  14.500  14.500  92.910    X  None   \n",
       "1  AA-         0        5.4   3.600   3.600  82.309    X  None   \n",
       "2   AA         0        3.3   9.730   9.730  74.920    X  None   \n",
       "3  AA-         0        3.6   6.650   6.650  85.553    X  None   \n",
       "4  AA-         0        7.0   6.300   6.300  76.640    X  None   \n",
       "\n",
       "               更新日期  \n",
       "0  2020-11-02 15:03  \n",
       "1  2020-11-02 15:03  \n",
       "2  2020-11-02 15:03  \n",
       "3  2020-11-02 15:03  \n",
       "4  2020-11-02 15:03  \n",
       "\n",
       "[5 rows x 27 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 171,
   "metadata": {},
   "outputs": [],
   "source": [
    "pct = df['可转债涨幅']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 172,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      -3.31\n",
       "1      -0.03\n",
       "2       3.70\n",
       "3       0.41\n",
       "4      -2.03\n",
       "       ...  \n",
       "300    -8.89\n",
       "301   -15.66\n",
       "302     0.02\n",
       "303   -15.21\n",
       "304     0.30\n",
       "Name: 可转债涨幅, Length: 305, dtype: float64"
      ]
     },
     "execution_count": 172,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pct"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "label = [str(i) for i in range(-20,20,2)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Q-20',\n",
       " 'Q-18',\n",
       " 'Q-16',\n",
       " 'Q-14',\n",
       " 'Q-12',\n",
       " 'Q-10',\n",
       " 'Q-8',\n",
       " 'Q-6',\n",
       " 'Q-4',\n",
       " 'Q-2',\n",
       " 'Q0',\n",
       " 'Q2',\n",
       " 'Q4',\n",
       " 'Q6',\n",
       " 'Q8',\n",
       " 'Q10',\n",
       " 'Q12',\n",
       " 'Q14',\n",
       " 'Q16',\n",
       " 'Q18']"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "result = pd.qcut(pct, q=20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0                       (2.926, 14.2]\n",
       "1                       (2.926, 14.2]\n",
       "2                      (1.727, 2.926]\n",
       "3                    (-2.456, -1.978]\n",
       "4                       (2.926, 14.2]\n",
       "                    ...              \n",
       "299                   (-0.121, 0.021]\n",
       "300    (-20.601000000000003, -10.612]\n",
       "301                     (2.926, 14.2]\n",
       "302                  (-3.406, -2.456]\n",
       "303                 (-10.612, -6.293]\n",
       "Name: 可转债涨幅, Length: 304, dtype: category\n",
       "Categories (20, interval[float64]): [(-20.601000000000003, -10.612] < (-10.612, -6.293] < (-6.293, -3.406] < (-3.406, -2.456] ... (0.506, 0.887] < (0.887, 1.727] < (1.727, 2.926] < (2.926, 14.2]]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.08"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pct[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       (2.926, 14.2]\n",
       "1       (2.926, 14.2]\n",
       "2      (1.727, 2.926]\n",
       "3    (-2.456, -1.978]\n",
       "4       (2.926, 14.2]\n",
       "5       (2.926, 14.2]\n",
       "6     (-1.978, -1.47]\n",
       "7      (0.506, 0.887]\n",
       "8      (0.245, 0.506]\n",
       "9      (0.887, 1.727]\n",
       "Name: 可转债涨幅, dtype: category\n",
       "Categories (20, interval[float64]): [(-20.601000000000003, -10.612] < (-10.612, -6.293] < (-6.293, -3.406] < (-3.406, -2.456] ... (0.506, 0.887] < (0.887, 1.727] < (1.727, 2.926] < (2.926, 14.2]]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 254,
   "metadata": {},
   "outputs": [],
   "source": [
    "bins=list(range(-20,21))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 255,
   "metadata": {},
   "outputs": [],
   "source": [
    "bins.insert(0,-90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 256,
   "metadata": {},
   "outputs": [],
   "source": [
    "bins.append(90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 257,
   "metadata": {},
   "outputs": [],
   "source": [
    "# label = [str(b+1) for b in bins[:-1]]\n",
    "label = [str(b) for b in bins[:-1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 258,
   "metadata": {},
   "outputs": [],
   "source": [
    "result = pd.cut(pct,bins,ordered=True,labels=label)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 259,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       -4\n",
       "1       -1\n",
       "2        3\n",
       "3        0\n",
       "4       -3\n",
       "      ... \n",
       "300     -9\n",
       "301    -16\n",
       "302      0\n",
       "303    -16\n",
       "304      0\n",
       "Name: 可转债涨幅, Length: 305, dtype: category\n",
       "Categories (42, object): ['-90' < '-20' < '-19' < '-18' ... '17' < '18' < '19' < '20']"
      ]
     },
     "execution_count": 259,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 260,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[-90,\n",
       " -20,\n",
       " -19,\n",
       " -18,\n",
       " -17,\n",
       " -16,\n",
       " -15,\n",
       " -14,\n",
       " -13,\n",
       " -12,\n",
       " -11,\n",
       " -10,\n",
       " -9,\n",
       " -8,\n",
       " -7,\n",
       " -6,\n",
       " -5,\n",
       " -4,\n",
       " -3,\n",
       " -2,\n",
       " -1,\n",
       " 0,\n",
       " 1,\n",
       " 2,\n",
       " 3,\n",
       " 4,\n",
       " 5,\n",
       " 6,\n",
       " 7,\n",
       " 8,\n",
       " 9,\n",
       " 10,\n",
       " 11,\n",
       " 12,\n",
       " 13,\n",
       " 14,\n",
       " 15,\n",
       " 16,\n",
       " 17,\n",
       " 18,\n",
       " 19,\n",
       " 20,\n",
       " 90]"
      ]
     },
     "execution_count": 260,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "bins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 261,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       -4\n",
       "1       -1\n",
       "2        3\n",
       "3        0\n",
       "4       -3\n",
       "      ... \n",
       "300     -9\n",
       "301    -16\n",
       "302      0\n",
       "303    -16\n",
       "304      0\n",
       "Name: 可转债涨幅, Length: 305, dtype: category\n",
       "Categories (42, object): ['-90' < '-20' < '-19' < '-18' ... '17' < '18' < '19' < '20']"
      ]
     },
     "execution_count": 261,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 186,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-3\n",
      "-1\n",
      "3\n",
      "1\n",
      "-3\n",
      "-1\n",
      "3\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "3\n",
      "-1\n",
      "7\n",
      "3\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-3\n",
      "5\n",
      "-1\n",
      "3\n",
      "-1\n",
      "-5\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "-3\n",
      "1\n",
      "1\n",
      "-3\n",
      "3\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "3\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-7\n",
      "1\n",
      "-1\n",
      "-3\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-3\n",
      "3\n",
      "3\n",
      "1\n",
      "-3\n",
      "-5\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "5\n",
      "1\n",
      "1\n",
      "-1\n",
      "-7\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-5\n",
      "3\n",
      "1\n",
      "3\n",
      "1\n",
      "5\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "3\n",
      "1\n",
      "1\n",
      "-5\n",
      "-1\n",
      "3\n",
      "1\n",
      "3\n",
      "1\n",
      "-1\n",
      "1\n",
      "-5\n",
      "1\n",
      "-1\n",
      "-89\n",
      "-9\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "5\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-5\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "3\n",
      "1\n",
      "3\n",
      "-1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-3\n",
      "1\n",
      "-5\n",
      "1\n",
      "1\n",
      "1\n",
      "-3\n",
      "1\n",
      "-5\n",
      "-1\n",
      "-9\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "-13\n",
      "-1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "3\n",
      "-1\n",
      "1\n",
      "3\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-9\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-11\n",
      "-1\n",
      "1\n",
      "17\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-3\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "-1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "1\n",
      "-1\n",
      "7\n",
      "3\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "1\n",
      "-7\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "1\n",
      "-1\n",
      "-13\n",
      "-1\n",
      "-19\n",
      "-9\n",
      "-15\n",
      "1\n",
      "-15\n",
      "1\n"
     ]
    }
   ],
   "source": [
    "for i in result.values:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 262,
   "metadata": {},
   "outputs": [],
   "source": [
    "v= pd.value_counts(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "pandas.core.series.Series"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(v)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 263,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      132\n",
       "-1      61\n",
       "1       39\n",
       "2       14\n",
       "-2      14\n",
       "-3       7\n",
       "3        5\n",
       "-5       4\n",
       "-4       4\n",
       "-6       4\n",
       "-7       3\n",
       "-10      3\n",
       "5        2\n",
       "4        2\n",
       "-16      2\n",
       "-20      1\n",
       "-14      1\n",
       "-9       1\n",
       "-12      1\n",
       "-13      1\n",
       "-90      1\n",
       "7        1\n",
       "16       1\n",
       "6        1\n",
       "19       0\n",
       "15       0\n",
       "18       0\n",
       "-19      0\n",
       "-18      0\n",
       "-17      0\n",
       "17       0\n",
       "-15      0\n",
       "-11      0\n",
       "14       0\n",
       "13       0\n",
       "12       0\n",
       "-8       0\n",
       "11       0\n",
       "10       0\n",
       "9        0\n",
       "8        0\n",
       "20       0\n",
       "Name: 可转债涨幅, dtype: int64"
      ]
     },
     "execution_count": 263,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 181,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 181,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.loc['-19']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 264,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "result_dict={}\n",
    "for i in label:\n",
    "    if i == \"-90\":\n",
    "        j='-20+'\n",
    "    else:\n",
    "        j=i\n",
    "    result_dict[j]=v.loc[i]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 265,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'-20+': 1,\n",
       " '-20': 1,\n",
       " '-19': 0,\n",
       " '-18': 0,\n",
       " '-17': 0,\n",
       " '-16': 2,\n",
       " '-15': 0,\n",
       " '-14': 1,\n",
       " '-13': 1,\n",
       " '-12': 1,\n",
       " '-11': 0,\n",
       " '-10': 3,\n",
       " '-9': 1,\n",
       " '-8': 0,\n",
       " '-7': 3,\n",
       " '-6': 4,\n",
       " '-5': 4,\n",
       " '-4': 4,\n",
       " '-3': 7,\n",
       " '-2': 14,\n",
       " '-1': 61,\n",
       " '0': 132,\n",
       " '1': 39,\n",
       " '2': 14,\n",
       " '3': 5,\n",
       " '4': 2,\n",
       " '5': 2,\n",
       " '6': 1,\n",
       " '7': 1,\n",
       " '8': 0,\n",
       " '9': 0,\n",
       " '10': 0,\n",
       " '11': 0,\n",
       " '12': 0,\n",
       " '13': 0,\n",
       " '14': 0,\n",
       " '15': 0,\n",
       " '16': 1,\n",
       " '17': 0,\n",
       " '18': 0,\n",
       " '19': 0,\n",
       " '20': 0}"
      ]
     },
     "execution_count": 265,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 266,
   "metadata": {},
   "outputs": [],
   "source": [
    "gte_20 = pct[pct>=20].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 267,
   "metadata": {},
   "outputs": [],
   "source": [
    "result_dict.update({'20+':gte_20})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 268,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'-20+': 1,\n",
       " '-20': 1,\n",
       " '-19': 0,\n",
       " '-18': 0,\n",
       " '-17': 0,\n",
       " '-16': 2,\n",
       " '-15': 0,\n",
       " '-14': 1,\n",
       " '-13': 1,\n",
       " '-12': 1,\n",
       " '-11': 0,\n",
       " '-10': 3,\n",
       " '-9': 1,\n",
       " '-8': 0,\n",
       " '-7': 3,\n",
       " '-6': 4,\n",
       " '-5': 4,\n",
       " '-4': 4,\n",
       " '-3': 7,\n",
       " '-2': 14,\n",
       " '-1': 61,\n",
       " '0': 132,\n",
       " '1': 39,\n",
       " '2': 14,\n",
       " '3': 5,\n",
       " '4': 2,\n",
       " '5': 2,\n",
       " '6': 1,\n",
       " '7': 1,\n",
       " '8': 0,\n",
       " '9': 0,\n",
       " '10': 0,\n",
       " '11': 0,\n",
       " '12': 0,\n",
       " '13': 0,\n",
       " '14': 0,\n",
       " '15': 0,\n",
       " '16': 1,\n",
       " '17': 0,\n",
       " '18': 0,\n",
       " '19': 0,\n",
       " '20': 0,\n",
       " '20+': 0}"
      ]
     },
     "execution_count": 268,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result_dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 223,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0       -3\n",
       "1       -1\n",
       "2        3\n",
       "3        1\n",
       "4       -3\n",
       "      ... \n",
       "300     -9\n",
       "301    -15\n",
       "302      1\n",
       "303    -15\n",
       "304      1\n",
       "Name: 可转债涨幅, Length: 305, dtype: category\n",
       "Categories (21, object): ['-89' < '-19' < '-17' < '-15' ... '13' < '15' < '17' < '19']"
      ]
     },
     "execution_count": 223,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 187,
   "metadata": {},
   "outputs": [
    {
     "ename": "IndexingError",
     "evalue": "Too many indexers",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mIndexingError\u001b[0m                             Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-187-11e667b45cb5>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m     \u001b[0mresult_dict\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msetdefault\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m     \u001b[0mresult_dict\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m+=\u001b[0m\u001b[0mv\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m    871\u001b[0m                     \u001b[1;31m# AttributeError for IntervalTree get_value\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    872\u001b[0m                     \u001b[1;32mpass\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 873\u001b[1;33m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_tuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    874\u001b[0m         \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    875\u001b[0m             \u001b[1;31m# we by definition only have the 0th axis\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_getitem_tuple\u001b[1;34m(self, tup)\u001b[0m\n\u001b[0;32m   1047\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1048\u001b[0m         \u001b[1;31m# no multi-index, so validate all of the indexers\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1049\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_has_valid_tuple\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mtup\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   1050\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1051\u001b[0m         \u001b[1;31m# ugly hack for GH #836\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\anaconda\\lib\\site-packages\\pandas\\core\\indexing.py\u001b[0m in \u001b[0;36m_has_valid_tuple\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m    698\u001b[0m         \u001b[1;32mfor\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mk\u001b[0m \u001b[1;32min\u001b[0m \u001b[0menumerate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    699\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m>=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 700\u001b[1;33m                 \u001b[1;32mraise\u001b[0m \u001b[0mIndexingError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m\"Too many indexers\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    701\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    702\u001b[0m                 \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_validate_key\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mk\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mIndexingError\u001b[0m: Too many indexers"
     ]
    }
   ],
   "source": [
    "result_dict ={}\n",
    "for ,index,i in enumerate(result):\n",
    "    result_dict.setdefault(i,0)\n",
    "    result_dict[i]+=v.loc[]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 227,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 227,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pct[pct>=19].count()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "304"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(pct)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(-2, 0]       135\n",
       "(0, 2]         66\n",
       "(-4, -2]       33\n",
       "(2, 4]         17\n",
       "(-6, -4]       11\n",
       "(-8, -6]        7\n",
       "(-14, -12]      7\n",
       "(-10, -8]       7\n",
       "(-12, -10]      5\n",
       "(4, 6]          5\n",
       "(-20, -18]      3\n",
       "(6, 8]          3\n",
       "(-18, -16]      2\n",
       "(-90, -20]      1\n",
       "(10, 12]        1\n",
       "(14, 16]        1\n",
       "(16, 18]        0\n",
       "(8, 10]         0\n",
       "(-16, -14]      0\n",
       "(12, 14]        0\n",
       "(18, 90]        0\n",
       "Name: 可转债涨幅, dtype: int64"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "303"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Interval(-90, -20, closed='right')"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "v.index.categories[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_list = []\n",
    "for k,v in result_dict.items():\n",
    "    y_list.append({'value':v,'percent':v})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 251,
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "EOL while scanning string literal (<ipython-input-251-cfba4fc523af>, line 14)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-251-cfba4fc523af>\"\u001b[1;36m, line \u001b[1;32m14\u001b[0m\n\u001b[1;33m    \"function(x){return Number(x.data.percent * 10,\u001b[0m\n\u001b[1;37m                                                   ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m EOL while scanning string literal\n"
     ]
    }
   ],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.commons.utils import JsCode\n",
    "from pyecharts.globals import ThemeType\n",
    "\n",
    "c = (\n",
    "    Bar(init_opts=opts.InitOpts(theme=ThemeType.LIGHT))\n",
    "    .add_xaxis('distributed',list(result_dict.keys()))\n",
    "    .add_yaxis(\"product1\", list(result_dict.values()), stack=\"stack1\")\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(\n",
    "            position=\"right\",\n",
    "            formatter=JsCode(\n",
    "                \"function(x){return Number(x.data.percent * 10,\n",
    "        )\n",
    "    )\n",
    "    .render(\"stack_bar_percent.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "x=list(result_dict.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 114,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 114,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [],
   "source": [
    "y=list(result_dict.values())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 115,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 115,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(y)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 297,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "# 可以，测试用的\n",
    "\n",
    "y_list = []\n",
    "for k,v in result_dict.items():\n",
    "    if k.startswith('-'):\n",
    "        color_=\"#FF0000\"\n",
    "\n",
    "    else:\n",
    "        color_=\"#228B22\"\n",
    "    y_list.append(opts.BarItem(\n",
    "    name=str(v),\n",
    "    value=int(v),\n",
    "    itemstyle_opts=opts.ItemStyleOpts(color=color_),\n",
    "))\n",
    "    \n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis(list(result_dict.keys()))\n",
    "    .add_yaxis(\"可转债价格分布\", y_list,category_gap=3)\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(is_show=True),\n",
    "        axispointer_opts=opts.AxisPointerOpts(is_show=True))\n",
    "    .set_global_opts(\n",
    "                    title_opts=opts.TitleOpts(title=\"可转债价格分布\"),\n",
    "                     xaxis_opts=opts.AxisOpts(\n",
    "                         name=\"涨跌幅\",\n",
    "                         is_show=True,\n",
    "                         name_rotate=30,\n",
    "                         interval=1,\n",
    "                         min_interval=1,\n",
    "                         max_interval=1,\n",
    " axisline_opts=opts.AxisLineOpts(\n",
    "                is_show=True,\n",
    "                is_on_zero=True,\n",
    "                on_zero_axis_index=0,\n",
    "                symbol=None,\n",
    "                linestyle_opts=opts.LineStyleOpts(\n",
    "                    is_show=True,\n",
    "                    width=1,\n",
    "                    opacity=1,\n",
    "                    curve=0,\n",
    "                    type_=\"solid\",\n",
    "                    color=None,\n",
    "                )\n",
    "            ),\n",
    "                         axislabel_opts=opts.LabelOpts(\n",
    "                is_show=True,  # bool\n",
    "                position=\"top\",  # Union[str, Sequence]\n",
    "                color='red',  # Optional[str]\n",
    "                font_size=None,  # Optional[Numeric]\n",
    "                font_style=None,  # Optional[str]\n",
    "                font_weight=None,  # Optional[str]\n",
    "                font_family=None,  # Optional[str]\n",
    "                rotate=0,  # Optional[Numeric]\n",
    "                margin=8,  # Optional[Numeric]\\,\n",
    "                interval=None,  # Union[Numeric, str, None]\n",
    "                horizontal_align=None,  # Optional[str]\n",
    "                vertical_align=None,  # Optional[str]\n",
    "                     )),\n",
    ")\n",
    "    .render(\"bar_stack0.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "numpy.int64"
      ]
     },
     "execution_count": 130,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "type(y[0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {},
   "outputs": [],
   "source": [
    "y_int = list(map(int,y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[1, 3, 2, 0, 7, 5, 7, 7, 11, 33, 135, 66, 17, 5, 3, 0, 1, 0, 1, 0, 0]"
      ]
     },
     "execution_count": 132,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_int"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 163,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "304"
      ]
     },
     "execution_count": 163,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sum(y_int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "metadata": {},
   "outputs": [],
   "source": [
    "result_ = []\n",
    "for i in y_int:\n",
    "    result_.append({'value':i,'name':i})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 155,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "black\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n",
      "red\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 146,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[<pyecharts.options.charts_options.BarItem at 0x18f2bac0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f2b3c0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19329fc0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37640>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f379c0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37dc0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37e00>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37940>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37a80>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37ac0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f37880>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19681bc0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19687940>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f357c0>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f35e80>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x1968f540>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19140240>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19140200>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x19140080>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f27440>,\n",
       " <pyecharts.options.charts_options.BarItem at 0x18f27a00>]"
      ]
     },
     "execution_count": 146,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "y_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 151,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "\n",
    "x = Faker.dogs + Faker.animal\n",
    "xlen = len(x)\n",
    "y = []\n",
    "for idx, item in enumerate(x):\n",
    "    if idx <= xlen / 2:\n",
    "        y.append(\n",
    "            opts.BarItem(\n",
    "                name=item,\n",
    "                value=(idx + 1) * 10,\n",
    "                itemstyle_opts=opts.ItemStyleOpts(color=\"#749f83\"),\n",
    "            )\n",
    "        )\n",
    "    else:\n",
    "        y.append(\n",
    "            opts.BarItem(\n",
    "                name=item,\n",
    "                value=(xlen + 1 - idx) * 10,\n",
    "                itemstyle_opts=opts.ItemStyleOpts(color=\"#d48265\"),\n",
    "            )\n",
    "        )\n",
    "\n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis(x)\n",
    "    .add_yaxis(\"series0\", y, category_gap=0, color=Faker.rand_color())\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"Bar-直方图（颜色区分）\"))\n",
    "    .render(\"bar_histogram_color.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 293,
   "metadata": {},
   "outputs": [],
   "source": [
    "from random import randint\n",
    "\n",
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.commons.utils import JsCode\n",
    "\n",
    "x_data = ['分类1',\n",
    "          '分类2',\n",
    "          '分类3',\n",
    "          '分类4',\n",
    "          '分类5',\n",
    "          '分类6',\n",
    "          '分类7',\n",
    "          '分类8',\n",
    "          '分类9',\n",
    "          '分类10',\n",
    "          ]\n",
    "\n",
    "y1_data = [0.72,\n",
    "           0.61,\n",
    "           0.98,\n",
    "           0.92,\n",
    "           0.67,\n",
    "           0.87,\n",
    "           0.6,\n",
    "           0.75,\n",
    "           0.96,\n",
    "           0.68\n",
    "           ]\n",
    "\n",
    "y2_data = [d * randint(1, 10) for d in y1_data]\n",
    "\n",
    "instance_bar = (\n",
    "    Bar()\n",
    "        .add_xaxis(xaxis_data=x_data)\n",
    "        .add_yaxis(series_name='系列1',\n",
    "                   y_axis=y1_data)\n",
    "        .add_yaxis(series_name='系列2',\n",
    "                   y_axis=y2_data)\n",
    "        .set_global_opts(\n",
    "        xaxis_opts=opts.AxisOpts(\n",
    "            type_='category',  # Optional[str]\n",
    "            name='坐标轴名称',  # Optional[str]\n",
    "            is_show=True,  # bool\n",
    "            is_scale=False,  # bool\n",
    "            is_inverse=True,  # bool\n",
    "            name_location='start',  # str\n",
    "            name_gap=15,  # Numeric\n",
    "            name_rotate=20,  # Optional[Numeric]\n",
    "            name_textstyle_opts=opts.TextStyleOpts(\n",
    "                color='blue',  # Optional[str]\n",
    "                font_style=None,  # Optional[str]\n",
    "                font_weight=None,  # Optional[str]\n",
    "                font_family=None,  # Optional[str]\n",
    "                font_size=None,  # Optional[Numeric]\n",
    "                align=None,  # Optional[str]\n",
    "                vertical_align=None,  # Optional[str]\n",
    "                line_height=None,  # Optional[str]\n",
    "                background_color='yellow',  # Optional[str]\n",
    "                border_color=None,  # Optional[str]\n",
    "                border_width=None,  # Optional[Numeric]\n",
    "                border_radius=None,  # Union[Numeric, Sequence, None]\n",
    "                padding=None,  # Union[Numeric, Sequence, None]\n",
    "                shadow_color=None,  # Optional[str]\n",
    "                shadow_blur=None,  # Optional[Numeric]\n",
    "                width=None,  # Optional[str]\n",
    "                height=None,  # Optional[str]\n",
    "                rich=None,  # Optional[dict]\n",
    "            ),\n",
    "            interval=30,  # Optional[Numeric]\n",
    "            grid_index=0,  # Numeric\n",
    "            position='',  # Optional[str]\n",
    "            offset=0,  # Numeric\n",
    "            split_number=5,  # Numeric\n",
    "            boundary_gap='',  # Union[str, bool, None]\n",
    "            min_='',  # Union[Numeric, str, None]\n",
    "            max_='',  # Union[Numeric, str, None]\n",
    "            min_interval=0,  # Numeric\n",
    "            max_interval=0,  # Optional[Numeric]\n",
    "            axisline_opts=opts.AxisLineOpts(\n",
    "                is_show=True,\n",
    "                is_on_zero=True,\n",
    "                on_zero_axis_index=0,\n",
    "                symbol=None,\n",
    "                linestyle_opts=opts.LineStyleOpts(\n",
    "                    is_show=True,\n",
    "                    width=1,\n",
    "                    opacity=1,\n",
    "                    curve=0,\n",
    "                    type_=\"solid\",\n",
    "                    color=None,\n",
    "                )\n",
    "            ),\n",
    "            axistick_opts=opts.AxisTickOpts(\n",
    "                is_show=True,\n",
    "                is_align_with_label=True,\n",
    "                is_inside=True,\n",
    "                length=20,\n",
    "                linestyle_opts=opts.LineStyleOpts(\n",
    "                    is_show=True,\n",
    "                    width=1,\n",
    "                    opacity=1,\n",
    "                    curve=0,\n",
    "                    type_=\"solid\",\n",
    "                    color=None,\n",
    "                )\n",
    "            ),\n",
    "            axislabel_opts=opts.LabelOpts(\n",
    "                is_show=True,  # bool\n",
    "                position=\"top\",  # Union[str, Sequence]\n",
    "                color='pink',  # Optional[str]\n",
    "                font_size=None,  # Optional[Numeric]\n",
    "                font_style=None,  # Optional[str]\n",
    "                font_weight=None,  # Optional[str]\n",
    "                font_family=None,  # Optional[str]\n",
    "                rotate=10,  # Optional[Numeric]\n",
    "                margin=8,  # Optional[Numeric]\\,\n",
    "                interval=None,  # Union[Numeric, str, None]\n",
    "                horizontal_align=None,  # Optional[str]\n",
    "                vertical_align=None,  # Optional[str]\n",
    "                formatter=JsCode(\"\"\"\n",
    "                function(value,index) {\n",
    "                  if (index === 2) {\n",
    "                    return 'formatter';\n",
    "                  } else {\n",
    "                    return value;\n",
    "                  }\n",
    "                }\n",
    "                \"\"\"),  # Optional[JSFunc] 回调函数\n",
    "                # 字符串模板 formatter='-{value}-',\n",
    "                background_color=None,  # Optional[str]\n",
    "                border_color=None,  # Optional[str]\n",
    "                border_width=None,  # Optional[Numeric]\n",
    "                border_radius=None,  # Optional[Numeric]\n",
    "                rich=None,  # Optional[dict]\n",
    "            ),\n",
    "            axispointer_opts=opts.AxisPointerOpts(\n",
    "                is_show=True,\n",
    "                link=None,\n",
    "                type_=\"line\",\n",
    "                label=None,\n",
    "                linestyle_opts=opts.LineStyleOpts(\n",
    "                    is_show=True,\n",
    "                    width=10,\n",
    "                    opacity=0.5,\n",
    "                    curve=0,\n",
    "                    type_=\"solid\",\n",
    "                    color='green',\n",
    "                ),\n",
    "            ),\n",
    "            splitarea_opts=opts.SplitAreaOpts(\n",
    "                is_show=True,\n",
    "                areastyle_opts=opts.AreaStyleOpts(\n",
    "                    opacity=0.05,\n",
    "                    color={\n",
    "                        'type': 'linear',\n",
    "                        'x': 0,\n",
    "                        'y': 0,\n",
    "                        'x2': 0,\n",
    "                        'y2': 1,\n",
    "                        'colorStops': [{\n",
    "                            'offset': 0, 'color': 'red'  # 0% 处的颜色\n",
    "                        }, {\n",
    "                            'offset': 1, 'color': 'blue'  # 100% 处的颜色\n",
    "                        }],\n",
    "                        'global': False  # 缺省为 false\n",
    "                    }\n",
    "                )\n",
    "\n",
    "            ),\n",
    "            splitline_opts=opts.SplitLineOpts(\n",
    "                is_show=True,\n",
    "                linestyle_opts=opts.LineStyleOpts(\n",
    "                    is_show=True,\n",
    "                    width=1,\n",
    "                    opacity=1,\n",
    "                    curve=0,\n",
    "                    type_=\"solid\",\n",
    "                    color='#0099ff',\n",
    "                )\n",
    "            )\n",
    "\n",
    "        )\n",
    "    ).render('test.html')\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 299,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pyecharts import options as opts\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts.faker import Faker\n",
    "\n",
    "\n",
    "y_list = []\n",
    "for k,v in result_dict.items():\n",
    "    if k.startswith('-'):\n",
    "        color_=\"#228B22\"        \n",
    "    else:\n",
    "        color_=\"#FF0000\"\n",
    "    y_list.append(opts.BarItem(\n",
    "    name=str(v),\n",
    "    value=int(v),\n",
    "    itemstyle_opts=opts.ItemStyleOpts(color=color_),\n",
    "))\n",
    "    \n",
    "c = (\n",
    "    Bar()\n",
    "    .add_xaxis(list(result_dict.keys()))\n",
    "    .add_yaxis(\"可转债价格分布\", y_list,category_gap=3)\n",
    "    .set_series_opts(\n",
    "        label_opts=opts.LabelOpts(is_show=True),\n",
    "        axispointer_opts=opts.AxisPointerOpts(is_show=True))\n",
    "    .set_global_opts(\n",
    "                    title_opts=opts.TitleOpts(title=\"可转债价格分布\"),\n",
    "                     xaxis_opts=opts.AxisOpts(\n",
    "                         name=\"涨跌幅\",\n",
    "                         is_show=True,\n",
    "                         name_rotate=30,\n",
    "                       ),\n",
    ")\n",
    "    .render(\"bar_stack0.html\")\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
